﻿using System.Collections;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using CommomFunctions;

namespace Pilhas
{
    public class Ellipses
    {
        /// <summary>
        ///numEllipses -> maximum number of elements in the stack
        ///ellipses -> contains the stack elements
        ///colors -> contains the colors of each element in the stack. Beside the different labels each element also has a distinct color
        /// </summary>
        private int numEllipses = 10; //número de ellipses desenhadas
        private ArrayList ellipses = new ArrayList();
        private ArrayList colors = new ArrayList();
                        
        public int numElements
        {
            get { return this.numEllipses; }
        }

        /// <summary>
        /// Creates the ellipses that represent each element of the stack. 
        /// Colors each element with the specified color. 
        /// All the elements are created at once. 
        /// Their visibility is what represents the push and pop operations.
        /// </summary>
        /// <param name="gd"></param>
        public void createEllipses(Grid gd)
        {
            fillCores();

            for (int i = 0; i < numEllipses; i++)
            {
                Ellipse tempEllipse = new Ellipse();
                gd.Children.Add(tempEllipse);
                ellipses.Add(tempEllipse);
            }

            foreach (Ellipse e in ellipses)
            {
                e.Visibility = Visibility.Hidden;
                e.Stroke = Brushes.Black;
                e.VerticalAlignment = VerticalAlignment.Bottom;
                e.HorizontalAlignment = HorizontalAlignment.Stretch;
                e.Fill = ((Brush)colors[ellipses.IndexOf(e)]);

                Grid.SetRow(e, 2);
                Grid.SetColumn(e, 0);
                Grid.SetColumnSpan(e, 3);
            }

            for (int i = 0; i < 10; i++)
            {
                ((Ellipse)(ellipses[i])).Margin = new Thickness(100, 0, 50, (39 * i));//20.0) * i);
                ((Ellipse)(ellipses[i])).Height = 37;//20.0; 1.54 é a proporção de 20/13 q era um tamanho q tinha ficado legal, ou seja, se eu tinha 13 ellipses eu dividia por 20 e ficava bom
            }
        }

        
        /// <summary>
        /// Fills the array "colors" with specific colors. Each color will be assigned to a different element in the stack.
        /// </summary>
        private void fillCores()
        {
            //  Fill="#FF E65160"
            colors.Add(BrushesAndEffects.convertePraRGB(230, 81, 96));
            //  Fill="#FF D015BA"
            colors.Add(BrushesAndEffects.convertePraRGB(208, 21, 186));
            //  Fill="#FF 9225CC"
            colors.Add(BrushesAndEffects.convertePraRGB(146, 37, 204));
            //  Fill="#FF 5D4BC1"
            colors.Add(BrushesAndEffects.convertePraRGB(93, 75, 193));
            //  Fill="#FF 166BE8"
            colors.Add(BrushesAndEffects.convertePraRGB(22, 107, 232));
            //  Fill="#FF 11D6CB"
            colors.Add(BrushesAndEffects.convertePraRGB(17, 214, 203));
            //  Fill="#FF 20DE48"
            colors.Add(BrushesAndEffects.convertePraRGB(32, 222, 72));
            //  Fill="#FF 4FF598"
            colors.Add(BrushesAndEffects.convertePraRGB(79, 245, 152));
            //  Fill="#FF EAE225"
            colors.Add(BrushesAndEffects.convertePraRGB(234, 226, 37));
            //  Fill="#FF EEA80F"
            colors.Add(BrushesAndEffects.convertePraRGB(238, 168, 15));
        }        
        
        /// <summary>
        /// Sets all ellipses visibility to hidden
        /// </summary>
        public void setAllHidden()
        {
            for (int i = 0; i < ellipses.Count; i++)
                ((Ellipse)ellipses[i]).Visibility = Visibility.Hidden;
        }

        /// <summary>
        /// Sets the specific visibility to the ellipse at index "ind".
        /// </summary>
        /// <param name="ind"></param>
        /// <param name="visibility"></param>
        public void setVisibility(int ind, Visibility visibility)
        {
            ((Ellipse)ellipses[ind]).Visibility = visibility;
        }
    }
}
